/**
 * 
 */
package mdb.com.vn.persist;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import mdb.com.vn.model.LuckyDraw;

/**
 * @author tu.dod
 *
 */
@Repository("luckyDrawDAO")
public class LuckyDrawDAOImpl extends AbstractHibernateDAOImpl<LuckyDraw, Integer> implements LuckyDrawDAO,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unchecked")
	@Override
	public List<LuckyDraw> findByRef(String transref) {
		// TODO Auto-generated method stub
		return getSession().getNamedQuery("LuckyDraw.findByRef").setString("transRef", transref).list();
	}

	@Override
	protected Class<LuckyDraw> getDomainClass() {
		// TODO Auto-generated method stub
		return LuckyDraw.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LuckyDraw> findByTypeAndRef(String transref, int type) {
		// TODO Auto-generated method stub
		return getSession().getNamedQuery("LuckyDraw.findByTypeAndRef").setString("transRef", transref).setInteger("ldrType", type).list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public int countAllLuckyDraw() {
		
		List<Long> longs = getSession().getNamedQuery("LuckyDraw.countAllLuckyDraw").list();
		if (longs.size() > 0){
			if(longs.get(0)!=null){
				return longs.get(0).intValue();
			}
		}
		return 0;
	}

	@Override
	public LuckyDraw findById(long id) {
		// TODO Auto-generated method stub
		return (LuckyDraw) getSession().get(LuckyDraw.class, id);
	}

}
